package myJs.user.missionManage

import myJs.CpLayer
import myJs.api.Api
import myJs.myPkg.ReactRouterDOM
import org.scalajs.dom.{URLSearchParams, document}
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
import shared.pojo.Pojo.EmailData
import slinky.core.FunctionalComponent
import slinky.core.annotations.react
import slinky.core.facade.Hooks.{useEffect, useState}
import slinky.web.html._

@react object Cp {

  val curPage = MissionManage

  type Props = Unit

  case class GVerify(kind: String, height: Double, width: Double)

  sealed trait ActiveStatus

  object NotGet extends ActiveStatus

  object HasActived extends ActiveStatus

  object NoActived extends ActiveStatus

  val component = FunctionalComponent[Props] { props =>
    val navigate = ReactRouterDOM.useNavigate()
    val location = ReactRouterDOM.useLocation()
    val searchParams = new URLSearchParams(location.search)
    val email = searchParams.get("email")
    val (activeStatus, setActiveStatus) = useState(NotGet: ActiveStatus)

    object FTool {

      def confirmActive = () => {
        val request = EmailData(email = email)
        Api.registerActive(request).map { response =>
          val curActiveStatus = response.hasActived match {
            case true => HasActived
            case false => NoActived
          }
          setActiveStatus(curActiveStatus)
        }
        ()
      }
    }

    useEffect(() => {
      FTool.confirmActive()
    }, List()
    )

    CpLayer(title = curPage.titleStr)(
      div(className := "page-content",
        div(className := "page-bar",
          ul(className := "page-breadcrumb",
            li(
              i(className := "fa fa-home"),
              a(href := "#", "首页")
            )
          )
        ),
        div(className := "row-fluid",
          div(className := "row",
            div(className := "col-sm-6",
              h4(
                b("您无此权限使用该系统，请与管理员联系!")
              )
            )

          )
        )
      )
    )

  }

}
